<%@page import="model.entity.Branch"%>
<%@page import="model.entity.Category"%>
<%@page import="model.entity.Product"%>
<%@page import="model.*"%>
<%@page import="java.util.List"%>
<%@page import="model.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="<c:url value="/views/admin/js/jquery-1.8.2.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/admin/js/tabifier.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/admin/js/js.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/admin/js/jPages.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/admin/js/highlight.pack.js"/>"></script>
  <script>
      function ConfirmDelete()
{
  var x = confirm("Are you sure you want to delete?");
  if (x)
      return true;
  else
    return false;
}
  </script>
  <script>
      function Confirm()
{
    var search = document.getElementById("cbo").value;
    if(search == "")
        {
            alert("Please choose a value");
            return false; 
        }
        
    else
        return true;
}
  </script>
  
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

  </script>
   <script>
  $(function(){
    $("div.holder").jPages({
      containerID : "movies",
      previous : "Pre",
      next : "Next",
      perPage : 10,
      delay : 20
    });
    
    
  });
  </script>

  <style type="text/css">
  table{ width: 960px; margin-top: 30px; }
  td, th{ text-align: left; height:25px; }
  th { background: #f5f5f5; }
  th:nth-child(1){ width:10%; }
  th:nth-child(2){ width:10%; }
  th:nth-child(3){ width:40%; }
  th:nth-child(4){ width:10%;}
  th:nth-child(5){ width:10%;}
  th:nth-child(6){ width:10%;}
  th:nth-child(7){ width:10%;}

  form { float: left; margin-right: 10px; }
  form  .category{ float: right; margin-right: 10px; }
  form label { margin-right: 5px; }
  form select { margin-right: 75px; }
  </style>
 <link href="<c:url value="/views/admin/css/jPages.css"/>" rel="stylesheet" type="text/css" />
  <link href="<c:url value="/views/admin/css/animate.css"/>" rel="stylesheet" type="text/css" />
   <link href="<c:url value="/views/admin/css/style.css"/>" rel="stylesheet" type="text/css" />
    <link href="<c:url value="/views/admin/css/github.css"/>" rel="stylesheet" type="text/css" />
<h2>Products</h2>
            
          
<p class="message1">
<%
                            String message = request.getAttribute("messageedit")==null ? "":request.getAttribute("messageedit").toString();
                        out.println(message);
%>
                    </p> 
                    <%
if(request.getAttribute("messageaddtobranch")!= null)
{
%>
<div class="notification success canhide">
            
                <p><strong>SUCCESS: </strong>
                This is a success message. Click me and I go away</p>
            </div>
<%}%>
<p class="message1">
<%
                            String message1 = request.getAttribute("messagecreate")==null ? "":request.getAttribute("messagecreate").toString();
                        out.println(message1);
%>
                 </p>
                 <p class="message1">
                 <%
                            String message2 = request.getAttribute("messagedelete")==null ? "":request.getAttribute("messagedelete").toString();
                        out.println(message2);
%>
                 </p>
                    <%
    CategoryImp cim = new CategoryImp();
    List<Category> listcategory = (List<Category>) cim.ChildCategory();
    BranchImp brim = new BranchImp();
    List<Branch> listbranch = (List<Branch>) brim.Branchs();
    List<Product> listproduct = (List<Product>) request.getAttribute("listproduct");
%>


<form onsubmit="return Confirm()" class="category" method="POST" action="<c:url value="" ></c:url>">
    <label for="cbo">Category :</label>
   
    <select name="categoryid" id="cbo" class="select">
        <option value="">Select Category</option>
            <%for(Category cat : listcategory)
                               {%>
                               <option  value="<%= cat.getCategoryid() %>" <%=request.getAttribute("catid")!=null && Integer.valueOf(request.getAttribute("catid").toString()) ==cat.getCategoryid() ? "selected='selected'" : ""  %> ><%= cat.getCategoryname() %></option>
            <%}%>
    </select>
    <input type="submit" class="submit" value="View Product">
</form>
<form onsubmit="return Confirm()" method="POST" action="<c:url value="" ></c:url>">
    <label for="cbo">Branch :</label>
   
    <select name="branchid" id="cbo" class="select">
        <option value="">Select branch</option>
            <%for(Branch branch : listbranch)
                               {%>
                               <option  value="<%= branch.getBranchid() %>" <%=request.getAttribute("catid")!=null && Integer.valueOf(request.getAttribute("catid").toString()) ==branch.getBranchid() ? "selected='selected'" : ""  %> ><%= branch.getBranchname() %></option>
            <%}%>
    </select>
    <input type="submit" class="submit" value="View Product">
</form>
  <div id="container" class="clearfix">

    <div id="content" class="defaults">

     

    <table width="100%" border="0" cellpadding="0" cellspacing="0" >
    <thead>
        <tr>
            <th width="10%" scope="col">Picture</th>    
            <th width="15%" scope="col">Category</th>
            <th width="35%" scope="col">Name</th>
            <th width="10%" scope="col">Unit Cost</th>
            <th width="16%" scope="col">Total amount</th>
            <th width="6%" scope="col">Quantity</th>
            <th width="8%" scope="col">Option</th>
        </tr>
    </thead>
        <tbody id="movies">
           
<%
if(listproduct.size() >0)
{       
for(Product list: listproduct)
               {
%> 
        <tr>
       
            
            <td scope="col">  
                <img src="<c:url value="<%= "/images/product/" + list.getPicture() + "" %>"></c:url>" width="40" height="40" alt="Image1">   
            </td>
            <td scope="col"><%= cim.DetailCategory(list.getCategoryid()).getCategoryname() %></td>
            <td scope="col"><%= list.getProductname() %></td>
            <td scope="col"><%= list.getUnitcost() %></td>
            <td scope="col"><%= list.getTotalamount() %></td>
            <td scope="col"><%= list.getQuantity() %></td>
            <td scope="col">
                <form action="<c:url value="admin/product/delete"/>" method="POST">
                    <a onclick="return ConfirmDelete();" href="<c:url value="<%= "/admin/product/delete/" + list.getProductid() %>">
                       
                   </c:url>"><img src="<c:url value="/views/admin/images/icondock/page_white_delete.png"/>" title="Delete"/></a> 
                   <a href="<c:url value="<%= "/admin/product/edit/" + list.getProductid() %>">        
                      
                      </c:url>"/><img title="Edit" src="<c:url value="/views/admin/images/icondock/page_white_edit.png"/>"/></a>
                      <a href="<c:url value="<%= "/admin/branchproduct/add/" + list.getProductid() %>"></c:url>">
                          <img title="Add to branch" src="<c:url value="/views/admin/images/icondock/action_add.png"/>"/>
                      </a>
                </form> 
                  
            </td>
        </tr>  
                  
<%
    }}else{
%> 
        <tr>
            Product is empty
        </tr>
<%}%>
    </tbody>
    </table>
     
<div class="holder"></div>
     

    </div> <!--! end of #content -->
  </div> <!--! end of #container -->          
    <div class="clearfix">&nbsp;</div>

    
  
    

 
<div class="clearfix">&nbsp;</div>
